package com.hd.controller.sqlexcel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hd.controller.base.BaseController;
import com.hd.entity.sqlexcel.SqlExcelField;
import com.hd.service.sqlexcel.SqlExcelFieldService;

/**
* sql导出excel表字段
*/
@RequestMapping("sqlExcelField")
@Controller
public class SqlExcelFieldController extends BaseController {
    @Autowired
    private SqlExcelFieldService sqlExcelFieldService;
    /**
     * 主页
     * @return
     */
    @RequestMapping("manager")
    public String manager() {
        return "jsp/report/sqlExcelField/sqlExcelFieldList";
    }
    /**
     * 列表
     * @return
     */
    @RequestMapping(value="/dataGrid",method=RequestMethod.POST)
    @ResponseBody
    public Object findAllByFId(String fid) {
        return sqlExcelFieldService.findAllByFId(fid);
    }

    /**
     * 添加页
     * @return
     */
    @RequestMapping("/addPage")
    public String addPage(String fid,Model model) {
        model.addAttribute("fid",fid);
        return "jsp/report/sqlExcelField/sqlExcelFieldAdd";
    }

    /**
     * 添加
     * @param sqlExcelField
     * @return
     */
    @RequestMapping(value="/add",method=RequestMethod.POST)
    @ResponseBody
    public Object add(SqlExcelField sqlExcelField) {
        sqlExcelFieldService.save(sqlExcelField);
        return renderSuccess("添加成功！");
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.POST)
    @ResponseBody
    public Object delete(@PathVariable("id") String id) {
        sqlExcelFieldService.delete(id);
        return renderSuccess("删除成功！");
    }
    /**
     * 编辑页
     * @param model
     * @param id
     * @return
     */
    @RequestMapping("/editPage/{id}")
	public String editPage(Model model, @PathVariable("id")String id) {
	 SqlExcelField sqlExcelField = sqlExcelFieldService.get(id);
        model.addAttribute("sqlExcelField", sqlExcelField);
        return "jsp/report/sqlExcelField/sqlExcelFieldEdit";
    }

    /**
     * 查看页
     * @param model
     * @param id
     * @return
     */
    @RequestMapping("/viewPage/{id}")
    public String viewPage(Model model, @PathVariable("id") String id) {
        SqlExcelField sqlExcelField = sqlExcelFieldService.get(id);
        model.addAttribute("sqlExcelField", sqlExcelField);
        return "jsp/report/sqlExcelField/sqlExcelFieldView";
    }
    /**
     * 编辑
     * @param sqlExcelField
     * @return
     */
    @RequestMapping(value = "/edit",method = RequestMethod.POST)
    @ResponseBody
    public Object edit(SqlExcelField sqlExcelField) {
        sqlExcelFieldService.update(sqlExcelField);
        return renderSuccess("编辑成功！");
    }


}
